package com.zhenwei.zscm.config.interceptors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class ApiConfig implements WebMvcConfigurer {
    @Autowired
    private RequestInterceptor requestInterceptor;
    @Autowired
    private PermissionInterceptor permissionInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有，请求排除静态资源
        registry.addInterceptor(requestInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/error",
                        "/public/**",
                        "/swagger-ui/**",
                        "/v3/api-docs/**",
                        "/api/user/login",
                        "/api/order/customerSearch",
                        "/api/captcha/generate"
                );
        registry.addInterceptor(permissionInterceptor).addPathPatterns("/**")
                .excludePathPatterns(
                        "/error",
                        "/public/**",
                        "/swagger-ui/**",
                        "/v3/api-docs/**",
                        "/api/user/login",
                        "/api/order/customerSearch",
                        "/api/captcha/generate"
                );
    }
}
